﻿using Microsoft.AspNetCore.Mvc;
using SD.Infrastructure.DTOBase;
using SD.Toolkits.AspNetCore.Attributes;
using SlamDunk.MES.IAppService.DTOs.Inputs;
using SlamDunk.MES.IAppService.DTOs.Outputs.QualityContext;
using SlamDunk.MES.IAppService.Interfaces;
using SlamDunk.ValueObjects.Enums;
using System;
using System.Collections.Generic;

namespace SlamDunk.MES.AppService.Host.Controllers
{
    /// <summary>
    /// 质量管理服务WebApi接口
    /// </summary>
    [ApiController]
    [Route("Api/[controller]/[action]")]
    public class QualityController : ControllerBase
    {
        #region # 字段及构造器

        /// <summary>
        /// 质量管理服务契约接口
        /// </summary>
        private readonly IQualityContract _qualityContract;

        /// <summary>
        /// 依赖注入构造器
        /// </summary>
        public QualityController(IQualityContract qualityContract)
        {
            this._qualityContract = qualityContract;
        }

        #endregion


        //命令部分

        #region # 创建作业计划质量检查 —— void CreateExecutionPlanInspect(string inspectionNo...
        /// <summary>
        /// 创建作业计划质量检查
        /// </summary>
        /// <param name="inspectionNo">质量检查编号</param>
        /// <param name="inspectionName">质量检查名称</param>
        /// <param name="inspectedDate">质检日期</param>
        /// <param name="executionPlanId">作业计划Id</param>
        /// <param name="description">描述</param>
        /// <param name="detailParams">质量检查明细参数模型集</param>
        [HttpPost]
        [WrapPostParameters]
        public void CreateExecutionPlanInspect(string inspectionNo, string inspectionName, DateTime inspectedDate, Guid executionPlanId, string description, IEnumerable<QualityInspectionDetailParam> detailParams)
        {
            this._qualityContract.CreateExecutionPlanInspect(inspectionNo, inspectionName, inspectedDate, executionPlanId, description, detailParams);
        }
        #endregion

        #region # 创建工单质量检查 —— void CreateWorkOrderInspect(string inspectionNo...
        /// <summary>
        /// 创建工单质量检查
        /// </summary>
        /// <param name="inspectionNo">质量检查编号</param>
        /// <param name="inspectionName">质量检查名称</param>
        /// <param name="inspectedDate">质检日期</param>
        /// <param name="workOrderId">工单Id</param>
        /// <param name="description">描述</param>
        /// <param name="detailParams">质量检查明细参数模型集</param>
        [HttpPost]
        [WrapPostParameters]
        public void CreateWorkOrderInspect(string inspectionNo, string inspectionName, DateTime inspectedDate, Guid workOrderId, string description, IEnumerable<QualityInspectionDetailParam> detailParams)
        {
            this._qualityContract.CreateWorkOrderInspect(inspectionNo, inspectionName, inspectedDate, workOrderId, description, detailParams);
        }
        #endregion

        #region # 修改质量检查 —— void UpdateQualityInspection(Guid qualityInspectionId...
        /// <summary>
        /// 修改质量检查
        /// </summary>
        /// <param name="qualityInspectionId">质量检查Id</param>
        /// <param name="inspectionName">质量检查名称</param>
        /// <param name="inspectedDate">质检日期</param>
        /// <param name="description">描述</param>
        /// <param name="detailParams">质量检查明细参数模型集</param>
        [HttpPost]
        [WrapPostParameters]
        public void UpdateQualityInspection(Guid qualityInspectionId, string inspectionName, DateTime inspectedDate, string description, IEnumerable<QualityInspectionDetailParam> detailParams)
        {
            this._qualityContract.UpdateQualityInspection(qualityInspectionId, inspectionName, inspectedDate, description, detailParams);
        }
        #endregion

        #region # 删除质量检查 —— void RemoveQualityInspection(Guid qualityInspectionId)
        /// <summary>
        /// 删除质量检查
        /// </summary>
        /// <param name="qualityInspectionId">质量检查Id</param>
        [HttpPost]
        [WrapPostParameters]
        public void RemoveQualityInspection(Guid qualityInspectionId)
        {
            this._qualityContract.RemoveQualityInspection(qualityInspectionId);
        }
        #endregion

        #region # 提交审核质量检查 —— void SubmitQualityInspection(Guid qualityInspectionId)
        /// <summary>
        /// 提交审核质量检查
        /// </summary>
        /// <param name="qualityInspectionId">质量检查Id</param>
        [HttpPost]
        [WrapPostParameters]
        public void SubmitQualityInspection(Guid qualityInspectionId)
        {
            this._qualityContract.SubmitQualityInspection(qualityInspectionId);
        }
        #endregion

        #region # 批量提交审核质量检查 —— void SubmitQualityInspections(IEnumerable<Guid>...
        /// <summary>
        /// 批量提交审核质量检查
        /// </summary>
        /// <param name="qualityInspectionIds">质量检查Id集</param>
        [HttpPost]
        [WrapPostParameters]
        public void SubmitQualityInspections(IEnumerable<Guid> qualityInspectionIds)
        {
            this._qualityContract.SubmitQualityInspections(qualityInspectionIds);
        }
        #endregion

        #region # 审核质量检查 —— void CheckQualityInspection(Guid qualityInspectionId...
        /// <summary>
        /// 审核质量检查
        /// </summary>
        /// <param name="qualityInspectionId">质量检查Id</param>
        /// <param name="passed">是否通过</param>
        /// <param name="checkedRemark">审核意见</param>
        [HttpPost]
        [WrapPostParameters]
        public void CheckQualityInspection(Guid qualityInspectionId, bool passed, string checkedRemark)
        {
            this._qualityContract.CheckQualityInspection(qualityInspectionId, passed, checkedRemark);
        }
        #endregion


        //查询部分

        #region # 分页获取作业计划质量检查列表 —— PageModel<ExecutionPlanInspectionInfo> GetExecutionPlanInspectionsByPage(...
        /// <summary>
        /// 分页获取作业计划质量检查列表
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="executionPlanId">作业计划Id</param>
        /// <param name="checkStatus">审核状态</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <returns>作业计划质量检查列表</returns>
        [HttpGet]
        public PageModel<ExecutionPlanInspectionInfo> GetExecutionPlanInspectionsByPage(string keywords, Guid? executionPlanId, CheckStatus? checkStatus, DateTime? startTime, DateTime? endTime, int pageIndex, int pageSize)
        {
            return this._qualityContract.GetExecutionPlanInspectionsByPage(keywords, executionPlanId, checkStatus, startTime, endTime, pageIndex, pageSize);
        }
        #endregion

        #region # 分页获取工单质量检查列表 —— PageModel<WorkOrderInspectionInfo> GetWorkOrderInspectionsByPage(...
        /// <summary>
        /// 分页获取工单质量检查列表
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="executionPlanId">作业计划Id</param>
        /// <param name="workOrderId">工单Id</param>
        /// <param name="checkStatus">审核状态</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <returns>工单质量检查列表</returns>
        [HttpGet]
        public PageModel<WorkOrderInspectionInfo> GetWorkOrderInspectionsByPage(string keywords, Guid? executionPlanId, Guid? workOrderId, CheckStatus? checkStatus, DateTime? startTime, DateTime? endTime, int pageIndex, int pageSize)
        {
            return this._qualityContract.GetWorkOrderInspectionsByPage(keywords, executionPlanId, workOrderId, checkStatus, startTime, endTime, pageIndex, pageSize);
        }
        #endregion

        #region # 获取质量检查明细列表 —— IEnumerable<QualityInspectionDetailInfo> GetQualityInspectionDetails(...
        /// <summary>
        /// 获取质量检查明细列表
        /// </summary>
        /// <param name="qualityInspectionId">质量检查Id</param>
        /// <returns>质量检查明细列表</returns>
        [HttpGet]
        public IEnumerable<QualityInspectionDetailInfo> GetQualityInspectionDetails(Guid qualityInspectionId)
        {
            return this._qualityContract.GetQualityInspectionDetails(qualityInspectionId);
        }
        #endregion
    }
}
